//
//  UIBarButtonItem.swift
//  MyWeiBo
//
//  Created by fangzhengwei on 2017/3/26.
//  Copyright © 2017年 fangzhengwei. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
 //MARK:为UIBarButtonItem提供便利构造函数
    convenience init(title : String,target : Any, selector : Selector , imgName : String? = nil) {
        self.init()
        let leftBtn = UIButton()
        leftBtn.setTitle(title, for: .normal)
        
        if imgName != nil {
            leftBtn.setImage(UIImage(named : imgName!), for: .normal)
        }
       
        leftBtn.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        leftBtn.setTitleColor(UIColor.darkGray, for: .normal)
        leftBtn.setTitleColor(UIColor.orange, for: .highlighted)
        leftBtn.sizeToFit()
//        customView?.addSubview(leftBtn)  错误代码
        //注意点
        customView = leftBtn
        
        leftBtn.addTarget(target, action: selector, for: .touchUpInside)
    }
    
    
}
